#!/bin/bash
species=$1
data_dir=$2
out_dir=$3

echo -e "${species}\t${data_dir}\t${out_dir}"

#mkdir -p ${out_dir}

# 拷贝需要分析的物种的数据，输入需要分析的含物种名的文件（--species），数据所在路径（--input），拷贝到的目标路径（--output）
#species.txt文件格式如下：
#Aal2
#Aan1
#Aar4



# 结果：在data目录下，以各个物种名为文件夹名下含有后续分析需要的四个文件
# 以Aal2物种为例，在data/Aal2目录下有pfam.table.txt、Aal2.bed、eggnog.emapper.annotations.all.txt、Aal2_mRNA_countsLength.txt文件
#001.copy_imp_files.py --species species.txt --input /data/genome/IMP --output data
001.copy_imp_files.py --species ${species} --input ${data_dir} --output ${out_dir}  

# 开启分析

# 创建结果文件夹
mkdir -p 01.cluster_result
mkdir -p 02.cluster_add_gene_info
mkdir -p 03.cluster_add_pfam_info
mkdir -p 04.prompt
mkdir -p 05.gene_cluster_glm_summary
mkdir -p 06.summary_labels_duplicate_to_list
mkdir -p 07.embedding_result
mkdir -p 08.split_file
mkdir -p 09.cluster_result
mkdir -p 10.llm_result
mkdir -p 11.sub_parent
mkdir -p 12.tree_concept_parent
mkdir -p 13.tree_annotation_to_table

cat ${species} | while read plant;do
	cat ${out_dir}/${plant}/${plant}_mRNA_countsLength.txt | while read name gene genome;do
		01.plant_gene_cluster_base_local_density.py -species ${plant} -base_num ${genome} -gene_num ${gene} -bed ${out_dir}/${plant}/${plant}.bed -output_table ./01.cluster_result
	done
	
	02.add_gene_info.py -cluster 01.cluster_result/${plant}___cluster_table_2.xlsx -gene ${out_dir}/${plant}/eggnog.emapper.annotations.all.txt -output 02.cluster_add_gene_info/${plant}___add_gene_info.xlsx

	03.add_pfam_info.py -cluster 02.cluster_add_gene_info/${plant}___add_gene_info.xlsx -pfam ${out_dir}/${plant}/pfam.table.txt -output 03.cluster_add_pfam_info/${plant}___add_pfam_info.xlsx

	04.cluster_prompt.py -input 03.cluster_add_pfam_info/${plant}___add_pfam_info.xlsx -output 04.prompt/${plant}.json

	05.gene_cluster_glm_4_summary_multipro.py -input 04.prompt/${plant}.json -output 05.gene_cluster_glm_summary/${plant}.xlsx -multi 50

	06.extrac_summary_labels.py -input 05.gene_cluster_glm_summary/${plant}.xlsx -output ./06.summary_labels_duplicate_to_list/${plant}.txt

	07.labels_embedding.py -label_input ./06.summary_labels_duplicate_to_list/${plant}.txt -output ./07.embedding_result/${plant}.json

	08.label_embedding_split.py -input ./07.embedding_result/${plant}.json -output ./08.split_file/${plant} -split_num 50
	
	# 构建结果文件夹
	mkdir -p 09.cluster_result/${plant}
	mkdir -p 10.llm_result/${plant}

	for i in {1..50};do
        	09.label_concept_tree_cluster.py -label_df ./08.split_file/${plant}/part_${i}.csv -concept_json ./menu_tree_to_dict_embedding.json -output_file 09.cluster_result/${plant}/part_${i}.json
	done

	for i in {1..50};do
        	10.llm_two_step_calssifiation.py -input ./09.cluster_result/${plant}/part_${i}.json -output ./10.llm_result/${plant}/part_${i}.json -multi 200
	done

	11.extrct_sub_parent.py -input ./10.llm_result/${plant} -output ./11.sub_parent/${plant}.json

	12.label_tree_concept_parent.py -tree_embedding ./menu_tree_to_dict_embedding.json -label_tree_concept ./11.sub_parent/${plant}.json -output ./12.tree_concept_parent/${plant}.json

	13.tree_annotation_to_table.py -add_pfam_table 03.cluster_add_pfam_info/${plant}___add_pfam_info.xlsx -cluster_table ./05.gene_cluster_glm_summary/${plant}.xlsx -concept_tree ./12.tree_concept_parent/${plant}.json -output ./13.tree_annotation_to_table/${plant}.xlsx

	14.generate_concept_circle.py -annotation_table ./13.tree_annotation_to_table/${plant}.xlsx -tree ./menu_tree_to_dict_embedding.json -concept_parent_all ./12.tree_concept_parent/${plant}.json -output_dir ./14.concept_circle

done

15.generate_density_json.py

16.generate_species_statistic_sql.py

17.generate_gene_sql.py

18.json_to_production.py





